package com.example.app08_listview;

import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.app08_listview.adapter.FoodInfo;
import com.example.app08_listview.adapter.MyBaseAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MainActivity
 * @author lijiguo
 */
public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        Log.i(TAG, "onCreate()");

        ListView lvMain = findViewById(R.id.lv_main);
        // 准备集合数据
        List<FoodInfo> data = new ArrayList<>(20);
        for (int i = 0; i < 20; i++) {
            data.add(new FoodInfo(R.drawable.food, "food-name-" + i, "food-content-" + i));
        }
        // 准备BaseAdapter对象，需要自己写实现类
        BaseAdapter adapter = new MyBaseAdapter(this, data);

        // 设置adapter
        lvMain.setAdapter(adapter);
    }
}